<template>
    <el-container>
        <el-header>
            <Mheader></Mheader>
        </el-header>
        <el-container>
            <el-aside width="200px">

                <el-menu :default-active="this.$route.path" router>
                    <el-menu-item v-for="(item,i) in navList" :key="i" :index="item.path">
                        {{ item.name }}
                    </el-menu-item>
                </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>

        </el-container>
    </el-container>
</template>

<script>
import router from "../router/index.js";
import Mheader from "../components/header/header";
import Tabar from "../components/tabar/tabar";
import Pages1 from "../pages/pages1/pages1";
import Pages4 from "../pages/pages1/pages4";
import findProject from "../pages/findProject";

import { mapGetters } from "vuex";
export default {
  components: {
    Mheader,
    Tabar,
    Pages1,
    findProject
  },
  name: "Home",
  created() {
    console.log(`test数据`, this.$store.state.test.test);
    // this.navList = this.$store.state.test.navList;
    this.$store.commit(`test/testFun`);
    // this.setRouter();
  },
  data() {
    return {
      activeIndex: "",
      //   navList: [],
      aaa: [],
      type: []
    };
  },
  computed: {
    // ...mapGetters(`test`, ["navList"])
    navList: function() {
       return this.$store.state.test.navList;
    
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    // 重置路由
    setRouter() {
      // http状态
      let code = 0;
      // 用户类型
      let type = 0;
      let state = window.localStorage.getItem("state");
      // 是否切换路由
      if ((code === 0) & (state === "login")) {
        console.log("用户已经登陆了，无需切换路由");
        this.navList = this.$store.state.router.typeA[0].children;
        this.aaa = this.$store.state.router.typeA;
        this.$router.addRoutes(this.aaa);
      } else if ((code === 0) & (state === "loginOut")) {
        console.log("用户已经退出了，无需切换路由");
      } else {
        console.log("用户第一次进来");
        if (type === 0) {
          this.navList = this.$store.state.router.typeA[0].children;
          this.aaa = this.$store.state.router.typeA;
          this.$router.addRoutes(this.aaa);

          console.log("type === 0");
        } else if (type === 1) {
          this.navList = this.$store.state.router.typeB[0].children;
          this.$router.addRoutes(this.navList);
          console.log("type === 1");
        } else {
          this.navList = this.$store.state.router.typeC[0].children;
          this.$router.addRoutes(this.navList);
          console.log("type === else");
        }
        window.localStorage.setItem("state", "login");
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
